package com.easy.sk.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SeckillActivity;
import com.easy.common.service.IProductService;
import com.easy.common.service.ISeckillActivityService;
import com.easy.common.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 秒杀活动表 前端控制器
 * </p>
 *
 * @author Easy
 * @since 2025-09-09
 */
@RestController
@RequestMapping("/skactivity")
public class SeckillActivityController {
    @Autowired
    private ISeckillActivityService iSeckillActivityService;
//    @DubboReference
//    IProductService iProductService;
    @GetMapping("{id}")
    public Result getOne(@PathVariable("id") Integer id){
        return Result.success(iSeckillActivityService.getById(id));
    }
    @GetMapping("page")
    public Result page(SeckillActivity seckillActivity, Page page){
        QueryWrapper<SeckillActivity> queryWrapper = new QueryWrapper<>(seckillActivity);
        return Result.success(iSeckillActivityService.page(page, queryWrapper));
    }
    @GetMapping("all")
    public Result findAll(){
        return Result.success(iSeckillActivityService.list());
    }
    @PostMapping
    public Result save(@RequestBody SeckillActivity seckillActivity){
        return Result.success(iSeckillActivityService.save(seckillActivity));
    }
    @PutMapping("/start/{id}")
    public Result start(@PathVariable("id") Integer id){
        return Result.success(iSeckillActivityService.start(id));
    }
    @PutMapping
    public Result update(@RequestBody SeckillActivity seckillActivity){
        return Result.success(iSeckillActivityService.updateById(seckillActivity));
    }
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success(iSeckillActivityService.removeById(id));
    }
}
